<cfcomponent output="false" displayName="ProjectDAO" hint="Does DAO for Projects.">

	
	<cffunction name="init" returntype="projects" access="public" output="false">
		<cfreturn this />
	</cffunction>
	
	<cffunction name="getProjects" access="public" returntype="query" output="false" 
				hint="I get all projects from the DB.">
		<cfquery name="qryProjects" datasource="#application.dsn#">
			SELECT  *
			FROM	projects
		</cfquery>
		
		<cfreturn qryProjects>
	</cffunction>
	
	<cffunction name="getProjectByID" access="public" returntype="query" output="false" 
				hint="I get a project from the DB based on the Id passed to me.">
		<cfargument name="projectid" type="string" required="yes" />
		<cfquery name="qryProjectByID" datasource="#application.dsn#">
			SELECT  *
			FROM	projects
			WHERE	projectid = <cfqueryparam value="#arguments.projectid#" cfsqltype="cf_sql_integer"/>
		</cfquery>
		
		<cfreturn qryProjectByID>
	</cffunction>
	

	<cffunction name="saveProject" access="public" returntype="void" output="true" 
				hint="I save a new project to the DB">
		<cfargument name="name" type="string" required="yes" />
		<cfargument name="url" type="string" required="yes" />
		<cfargument name="buildfile" type="string" required="yes" />
		<cfargument name="logfile" type="string" required="yes" />
		<cfargument name="baseVersion" type="string" required="yes" />
		<cfargument name="svnRootURL" type="string" required="yes" />
		<cfargument name="svnProjectURL" type="string" required="yes" />
		<cfargument name="svnTagURL" type="string" required="yes" />
		<cfargument name="svnUsername" type="string" required="yes" />
		<cfargument name="svnPassword" type="string" required="yes" />
		<cfargument name="createTag" type="string" required="yes" />
		<cfargument name="deploymentRoot" type="string" required="yes" />
		<cfargument name="deploymentPath" type="string" required="yes" />
		<cfargument name="buildRoot" type="string" required="yes" />
		
		<cfquery name="qrySaveProject" datasource="#application.dsn#">
			INSERT INTO projects (
				name,url,buildfile,logfile,baseversion,svnrooturl,svnprojecturl,svntagurl,svnusername,
				svnpassword,createtag,deploymentroot,deploymentpath,buildroot
			) VALUES (
				<cfqueryparam value="#arguments.name#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.url#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.buildfile#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.logfile#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.baseVersion#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.svnRootURL#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.svnProjectURl#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.svnTagURL#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.svnUsername#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.svnPassword#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.createTag#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.deploymentRoot#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.deploymentPath#" cfsqltype="cf_sql_varchar"/>,
				<cfqueryparam value="#arguments.buildRoot#" cfsqltype="cf_sql_varchar"/>
			)
		</cfquery>
	</cffunction>
	

	<cffunction name="updateProject" access="public" returntype="void" output="false" 
				hint="I update a project in the DB">
		<cfargument name="projectid" type="numeric" required="true">
		<cfargument name="name" type="string" required="yes" />
		<cfargument name="url" type="string" required="yes" />
		<cfargument name="buildfile" type="string" required="yes" />
		<cfargument name="logfile" type="string" required="yes" />
		<cfargument name="baseVersion" type="string" required="yes" />
		<cfargument name="svnRootURL" type="string" required="yes" />
		<cfargument name="svnProjectURL" type="string" required="yes" />
		<cfargument name="svnTagURL" type="string" required="yes" />
		<cfargument name="svnUsername" type="string" required="yes" />
		<cfargument name="svnPassword" type="string" required="yes" />
		<cfargument name="createTag" type="numeric" required="yes" />
		<cfargument name="deploymentRoot" type="string" required="yes" />
		<cfargument name="deploymentPath" type="string" required="yes" />
		<cfargument name="buildRoot" type="string" required="yes" />

		<cfquery name="qryUpdateProject" datasource="#application.dsn#">
			UPDATE projects 
			SET name = <cfqueryparam value="#arguments.name#" cfsqltype="cf_sql_varchar"/>,
				url = <cfqueryparam value="#arguments.url#" cfsqltype="cf_sql_varchar"/>,
				buildfile = <cfqueryparam value="#arguments.buildfile#" cfsqltype="cf_sql_varchar"/>,
				logfile = <cfqueryparam value="#arguments.logfile#" cfsqltype="cf_sql_varchar"/>,
				baseversion = <cfqueryparam value="#arguments.baseVersion#" cfsqltype="cf_sql_varchar"/>,
				svnrooturl = <cfqueryparam value="#arguments.svnRootURL#" cfsqltype="cf_sql_varchar"/>,
				svnprojecturl = <cfqueryparam value="#arguments.svnProjectURl#" cfsqltype="cf_sql_varchar"/>,
				svntagurl = <cfqueryparam value="#arguments.svnTagURL#" cfsqltype="cf_sql_varchar"/>,
				svnusername = <cfqueryparam value="#arguments.svnUsername#" cfsqltype="cf_sql_varchar"/>,
				svnpassword = <cfqueryparam value="#arguments.svnPassword#" cfsqltype="cf_sql_varchar"/>,
				createtag = <cfqueryparam value="#arguments.createTag#" cfsqltype="cf_sql_numeric"/>,
				deploymentroot = <cfqueryparam value="#arguments.deploymentRoot#" cfsqltype="cf_sql_varchar"/>,
				deploymentpath = <cfqueryparam value="#arguments.deploymentPath#" cfsqltype="cf_sql_varchar"/>,
				buildroot = <cfqueryparam value="#arguments.buildRoot#" cfsqltype="cf_sql_varchar"/>
			WHERE (projectid = <cfqueryparam value="#arguments.projectID#" cfsqltype="cf_sql_numeric"/>)
		</cfquery>
	</cffunction>
	
	<cffunction name="deleteProject" access="public" returntype="void" output="false" 
				hint="I delete a project from the DB.">
		<cfargument  name="projectid" type="numeric" required="true"/>
		<cfquery name="qryDeleteProject" datasource="#application.dsn#">
			DELETE FROM projects WHERE
			projectid = <cfqueryparam value="#arguments.projectid#" cfsqltype="cf_sql_integer"/>
		</cfquery>
	</cffunction>
	
</cfcomponent>